<template>
  <jm-page class="p-12px">
    <jm-search-grid
      ref="searchGridRef"
      @search="onSearch"
      @reset="onReset"
      :columns="pageConditions"
      :state="searchState"
    ></jm-search-grid>
    <jm-table
      ref="tableRef"
      :columns="columns"
      :apiParams="{}"
      :max-height="tableHeight"
      has-action
      :hasExport="false"
      @export="params => useDownload(excelExportToMinio, params)"
      respField="data.records"
      url="/dataApi/manager/getProductList"
    >
      <template #btns>
        <div class="text-right mr-10px flex items-center justify-end">
          <el-dropdown trigger="click">
            <el-button
              type="primary"
              class="mr-10px"
              icon="upload"
              size="small"
            >
              导入<el-icon class="el-icon--right"><arrow-down /></el-icon>
            </el-button>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>
                  <jm-import
                    accept=".xlsx,.xls"
                    url="/dataApi/manager/importExcel"
                    @success="onQuery()"
                  ></jm-import>
                </el-dropdown-item>
                <el-dropdown-item :icon="CirclePlusFilled">
                  <el-button
                    size="small"
                    @click="downloadFile(downloadTemplateUrl)"
                    link
                    type="primary"
                    >下载模板</el-button
                  >
                </el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <moreSearch />
        </div>
      </template>
      <template #shipmentsOrder="{ row }">
        <el-text
          class="cursor-pointer"
          type="primary"
          @click="showDialog(true, row)"
        >
          {{ row.shipmentsOrder }}</el-text
        >
      </template>
      <template #warehouseOrder="{ row }">
        <el-text type="primary" @click="showWarehouseDialog(true, row)">
          {{ row.warehouseOrder }}</el-text
        >
      </template>
    </jm-table>
  </jm-page>
  <shipmentsOrder v-if="isShow"></shipmentsOrder>
  <warehouseOrder v-if="warehouseShow"></warehouseOrder>
</template>
<script setup>
import { provide } from 'vue'
import moreSearch from './components/moreSearch.vue'
import shipmentsOrder from './components/shipmentsOrder.vue'
import warehouseOrder from './components/warehouseOrder.vue'
import { useSN } from './share'
import { useDownload } from '@/hooks/useDownload'
import { downloadFile } from '@/utils/file.js'
import { excelExportToMinio } from '@/api/modules/sn.js'

const downloadTemplateUrl = `${
  import.meta.env.VITE_BASE_URL
}/dataApi/manager/downloadTemplate`
const modules = useSN()

const {
  searchState,
  tableRef,
  onQuery,
  onReset,
  onSearch,
  searchGridRef,
  tableHeight,
  columns
} = modules.snIndexStore

const { pageConditions } = modules.moreSearchStore

const { showDialog, isShow } = modules.shipmentOrderStore

const { showWarehouseDialog, isShow: warehouseShow } =
  modules.warehouseOrderStore

provide('modules', modules)
</script>
<style lang="scss" scoped></style>
